<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function showMsg(){
				alert("我被点击");
			}
			
			window.onload = function(){
				var btn = document.querySelector("button");
				btn.onclick = showMsg;
			}
		</script>
	</head>
	<body>
<!-- 		<button onclick="showMsg()">按钮</button> -->
		<button>按钮</button>
	</body>
<!-- 	<script type="text/javascript">
			var btn = document.querySelector("button");
			btn.onclick = showMsg;
	</script> -->
</html>
